feat: add clearAll() API to CredentialsManager and deleteAllEntries() method CredentialsStorage#1116
Conversation
… to CredentialsStore
There was a problem hiding this comment.
Pull request overview
Adds a new “clear everything” capability to Auth0.swift’s Credentials Manager by extending the storage abstraction and documenting the change for v3 migration.
Changes:
- Add
CredentialsManager.clearAll() throwsto wipe all stored credential entries and reset the biometric session. - Extend
CredentialsStoragewithdeleteAllEntries() throws, including aSimpleKeychainimplementation. - Add test coverage and v3 migration guide entries for the new APIs.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| V3_MIGRATION_GUIDE.md | Documents the new clearAll / deleteAllEntries APIs and migration impact. |
| Auth0Tests/CredentialsManagerSpec.swift | Adds specs verifying clearAll() behavior and updates mocks for the new protocol requirement. |
| Auth0/CredentialsStorage.swift | Extends the storage protocol and implements deleteAllEntries() for SimpleKeychain. |
| Auth0/CredentialsManager.swift | Introduces clearAll() that resets biometric session and delegates to storage wipe. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Auth0/CredentialsManager.swift
Outdated
| /// Clears all credentials stored in the Keychain, including the main credentials and any API credentials | ||
| /// for all audiences. | ||
| /// | ||
| /// ## Usage | ||
| /// | ||
| /// ```swift | ||
| /// try credentialsManager.clearAll() | ||
| /// ``` | ||
| /// | ||
| /// - Throws: An error when the delete operation fails. | ||
| public func clearAll() throws { | ||
| #if WEB_AUTH_PLATFORM | ||
| self.biometricSession.lock.lock() | ||
| self.biometricSession.lastBiometricAuthTime = self.biometricSession.noSession | ||
| self.biometricSession.lock.unlock() | ||
| #endif | ||
| try self.storage.deleteAllEntries() |
Auth0/CredentialsStorage.swift
Outdated
| /// - Returns: If the entry was deleted. | ||
| func deleteEntry(forKey key: String) -> Bool | ||
|
|
||
| /// Deletes all storage entries. |
V3_MIGRATION_GUIDE.md
Outdated
|
|
||
| **New method:** `clearAll() throws` has been added to `CredentialsManager`. | ||
|
|
||
| This method removes **all** credentials stored by the Credentials Manager from the Keychain, including the default credentials entry, any API credentials stored via `store(apiCredentials:)`, and any SSO credentials. It also resets the biometric authentication session (if biometric authentication was enabled). |
There was a problem hiding this comment.
Changes look good however, We should test following flows if not tested already
- Happy Case: We have only credentials and no APICredentials and then it calls clearAll() API, and then it calls retrieveCredentials(scope) does it throw the correct error?
- MRRT flow and calling clear All and then we call following apis
- apiCredentials(forAudience) API, does it throw correct error.
- store(apiCredentials) , whats behavior in this
V3_MIGRATION_GUIDE.md
Outdated
|
|
||
| ```swift | ||
| // v2 - CredentialsStorage protocol | ||
| class MyCustomStorage: CredentialsStorage { |
There was a problem hiding this comment.
MyCustomCredentialStorage
There was a problem hiding this comment.
renamed MyCustomStorage to MyCustomCredentialStorage
@sanchitmehtagit Flow 2 (MRRT + clearAll): apiCredentials(forAudience:) after clearAll() → Correctly throws .noCredentials error Console logs confirming all flows: |
…uired when using clearAll()
📋 Changes
Added a new clearAll() throws API to CredentialsManager and a new deleteAllEntries() throws method to the CredentialsStorage protocol.
Types and methods added:
Usage:
Migration guide: Updated V3_MIGRATION_GUIDE.md with documentation for both new APIs, including migration examples for custom CredentialsStorage implementations.
📎 References
SDK-7983
🎯 Testing
Unit tests (3 new tests added to CredentialsManagerSpec):
Should clear all credentials from keychain — Stores credentials, calls clearAll(), verifies hasValid() returns false
Should not throw when keychain is already empty — Calls clearAll() on empty storage, verifies no error is thrown
Should throw when storage fails — Uses a mock storage that throws on deleteAllEntries(), verifies the error propagates
Manual testing (sample app on iPhone 17 Pro simulator):
Manual(Emulator)
Launched the app → checkAuthentication confirmed no credentials in keychain
Logged in via Web Auth → Verified credentials (access token, ID token, refresh token) were stored in keychain via CredentialsManager -> SimpleKeychain
Tapped "Clear All Credentials" → Verified SimpleKeychain.deleteAll() was called, all entries removed, biometric session reset, hasValid() = false
Tapped "Clear All Credentials" on empty keychain → Verified no error thrown, operation succeeds gracefully